<?php

use think\migration\Seeder;
use app\admin\model\ReceiveAddressModel;
use app\admin\model\MemberModel;
use think\Db;

class AddressSeeder extends Seeder
{

    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * http://docs.phinx.org/en/latest/seeding.html
     */
    public function run()
    {
        for ($i = 0; $i <= 10; $i++) {
            $address = new ReceiveAddressModel();
            $address->save($this->faker());
        }

    }

    public function faker()
    {

        $faker = Faker\Factory::create('zh_CN');

        $addresses = [
            ["北京市", "市辖区", "东城区"],
            ["河北省", "石家庄市", "长安区"],
            ["江苏省", "南京市", "浦口区"],
            ["江苏省", "苏州市", "相城区"],
            ["广东省", "深圳市", "福田区"],
        ];
        $address = $faker->randomElement($addresses);
        $member = MemberModel::column('id');
        return [
            //随机获取一个用户
            'member_id' => $member[array_rand($member)],
            'province'  => $address[0],
            'city'      => $address[1],
            'area'      => $address[2],
            'address'   => sprintf('第%d街道第%d号', $faker->randomNumber(2), $faker->randomNumber(3)),
            'zip'       => $faker->postcode,
            'name'      => $faker->name,
            'mobile'    => $faker->phoneNumber,
        ];
    }
}